package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayUserLevelDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayUserVocBoundLogDTO;
import com.cskaoyan.wordmemorize.dto.app.UserPageDTO;
import com.cskaoyan.wordmemorize.dto.app.UserVocBoundStatisticsDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserRemindCommand;
import com.cskaoyan.wordmemorize.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserMineController {

    @Autowired
    UserService userService;

    // APP端更新用户的学习提醒时间
    @PutMapping("remind")
    public Result updateUserRemind(@RequestBody UserRemindCommand command){
        userService.updateUserRemind(command);
        return Result.ok();
    }

    // APP端更新用户每天计划学习的单词量
    @PutMapping("day/voc")
    public Result updateVocCountOfDay(Integer count){
        // 获取正在访问的用户Id
        Long userId = StpKit.USER.getLoginIdAsLong();

        userService.updateVocCountOfDay(userId,count);
        return Result.ok();
    }

    // APP端获取用户我的页面展示的信息
    @GetMapping("voc/my/page")
    public Result<UserPageDTO> getUserPage(){
        // 获取正在访问的用户Id
        Long userId = StpKit.USER.getLoginIdAsLong();

        UserPageDTO userPage = userService.getUserPage(userId);
        return Result.ok(userPage);
    }

    // APP端获取用户的单词上限统计信息
    @GetMapping("voc/bound/statistics")
    public Result<UserVocBoundStatisticsDTO> getUserVocBoundStatistics(){
        // 获取正在访问的用户Id
        Long userId = StpKit.USER.getLoginIdAsLong();

        UserVocBoundStatisticsDTO userVocBoundStatistics = userService.getUserVocBoundStatistics(userId);
        return Result.ok(userVocBoundStatistics);
    }

    // APP端发获取用户的单词上限变化明细，如果未传分页信息则返回所有
    @GetMapping("voc/bound/detail")
    public Result<PageDTO<DisplayUserVocBoundLogDTO>> getUserVocBoundLog(PageRequest pageRequest){
        // 获取正在访问的用户Id
        Long userId = StpKit.USER.getLoginIdAsLong();

        PageDTO<DisplayUserVocBoundLogDTO> userVocBoundLog = userService.getUserVocBoundLog(pageRequest, userId);
        return Result.ok(userVocBoundLog);
    }

    // APP端获取用户等级信息(包括已达到等级和未达到等级)
    @GetMapping("level/info")
    public Result<DisplayUserLevelDTO> getUserLevelInfo(){
        // 获取正在访问的用户Id
        Long userId = StpKit.USER.getLoginIdAsLong();

        DisplayUserLevelDTO userLevelInfo = userService.getUserLevelInfo(userId);
        return Result.ok(userLevelInfo);
    }
}
